package com.lk.wz.dao.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lk.wz.dao.CateGoryDao;
import com.lk.wz.util.DBUtil;

public class CateGoryDaoImpl implements CateGoryDao{
	private final String GET_CATEGORY_LIST=
		"select a.name,b.name from category a inner join category b on a.id=b.pid";

	public Map<String, List<String>> getCateGoryList() {
		Connection conn=DBUtil.getConnection();
		Map<String,List<String>> map=new HashMap<String,List<String>>();
		try {
			Statement stat=conn.createStatement();
			ResultSet rs=stat.executeQuery(GET_CATEGORY_LIST);
			while(rs.next()){
				if(map.keySet().contains(rs.getString(1))){
					List<String> list=map.get(rs.getString(1));
					list.add(rs.getString(2));
				}else{
					List<String> list=new ArrayList<String>();
					list.add(rs.getString(2));
					map.put(rs.getString(1), list);
				}
			}
			rs.close();
			stat.close();
			DBUtil.closeConnection(conn);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return map;
	}
	
	
	public static void main(String[] args){
	}
	
}
